package command.respondente;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import model.Respondente;

import command.ICommand;
import dao.RespondenteDAO;

public class AtualizarRespondenteCommand implements ICommand{

	public String execute(HttpServletRequest request) throws ServletException,IOException {
		String nome = request.getParameter("nome");
		String matricula = request.getParameter("matricula");
		String endereco = request.getParameter("endereco");
		String cpf = request.getParameter("cpf");
		String email = request.getParameter("email");
		String cod = request.getParameter("codigo");
		int codigo = Integer.parseInt(cod);
		Respondente respondente = new Respondente(nome, endereco, matricula, cpf, email);
		respondente.setCodigo(codigo);
		RespondenteDAO dao = new RespondenteDAO();
		
		try {
			dao.atualizar(respondente);
			return "controller.do?acao=listarRespondente";
		} catch (SQLException e) {
			e.printStackTrace();
			return "/Gew/paginas/editar_respondente.jsp?erro=1";
		}
		
	}

}
